/** 
  *@CopyRight(c)2009 company Co.Ltd. 
  *@All right reserved.
  *@module name: App.Base.SystemManage.SystemUserTypeMgrWindow
  *@description:
  *
  *@author: lugj
  *@version: 1.0
  *@date: 2009/07/16
  *@last date: 2009/07/18
  *@history:
    1.
    2.
  *@bugs:
    1. 
    2. 
  *
*/ 

Ext.namespace("App.Base.SystemManage");

//SystemUserTypeMgrWindow Class
App.Base.SystemManage.SystemUserTypeMgrWindow = function(config){
	this.config = config;
	this.MODULE_ID = App.Base.Common.func.generateGlobalUniqueId(this.config, 'SYSUSERTYPEMGRWIN');

    this.setHandler = function(handler, scope){
        this.handler = handler;
        this.scope = scope;
    };
	this.setHandler(this.config.handler, this.config.scope);

	this.action = App.Base.common.param.BUTTON_ACTION_NONE;

	this.userTypeParentId = null;

	this.form = new Ext.form.FormPanel({
		border: false,
		autoScroll: true,
		frame: true,
		defaults: {width: 360},
		defaultType: 'textfield',
		labelAlign: 'top',
		labelWidth: 128,
		bodyStyle:'padding:5px 5px 5px 0',
		layout: 'form',
		items :[{
			id: 'userTypeName' + this.MODULE_ID,
			name: 'userTypeName' + this.MODULE_ID,
			fieldLabel: '<font color="red">用户类型名称 (必填 系统范围内必须唯一标识)</font>',
			maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
			regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
			regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS, 
			allowBlank: false
		},
		new Ext.Button({
			id: 'btnSelectParentId' + this.MODULE_ID,
			text: '<font color="red">选择上级用户类型 (必选)</font>',
			handler: function(){
				new App.Base.SystemManage.SystemSelectTreeWindow({
					id: this.MODULE_ID,
					title: '选择上级用户类型',
					leaf: '0',
					asyncTreeNode: {
						id: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_ID,
						text: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_NORMAL_TITLE,
						icon: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_NORMALICON_URL,
						expandIcon: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_EXPANDICON_URL,
						qtip: App.Base.common.param.SYSUSERTYPEMGR_TREE_ROOTNODE_QTIP,
						singleClickExpand: true
					},
					dataUrl: App.Base.common.param.SYSUSERTYPEMGR_ASYNC_TREELOADER_DATAURL,
					handler: function(o, node){
						if (o.action == App.Base.common.param.BUTTON_ACTION_OK)
						{
							var nodeId = node.id.substr(0, node.id.length - o.MODULE_ID.length);
							this.userTypeParentId = nodeId;
							Ext.getCmp('userTypeParentName' + this.MODULE_ID).setValue(node.text + App.Base.common.param.SPLIT_CHARS_UNDELINE + nodeId);
						}
					},
					scope: this
				}).getMainPanel().show();
			},
			scope: this
		}), {
			id: 'userTypeParentName' + this.MODULE_ID,
			name: 'userTypeParentName' + this.MODULE_ID,
			fieldLabel: '<font color="red">上级用户类型(必填)</font>',
			readOnly: true,
			disabled: true,
			hideLabel: true,
			maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
			regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
			regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
			allowBlank: false,
			emptyText : '请选上级用户类型...'
		}, {
			id: 'userTypeDesc' + this.MODULE_ID,
			name: 'userTypeDesc' + this.MODULE_ID,
			fieldLabel: '<font color="red">用户类型描述</font>',
			maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
			regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
			regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS
		}, {
			id: 'normalImgUrl' + this.MODULE_ID,
			name: 'normalImgUrl' + this.MODULE_ID,
			fieldLabel: '<font color="red">树显示的正常图标URL路径 (必填)</font>',
			maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
			regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
			regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
			allowBlank: false
		}, {
			xtype: 'textfield',
			id: 'expandImgUrl' + this.MODULE_ID,
			name: 'expandImgUrl' + this.MODULE_ID,
			fieldLabel: '<font color="red">树展开时的图标URL路径 (必填)</font>',
			maskRe: eval(App.Base.common.param.TEXTFIELD_INPUT_MASKRE),
			regex: eval(App.Base.common.param.TEXTFIELD_INPUT_REGEX),
			regexText: App.Base.common.param.TEXTFIELD_INPUT_REGEX_TIPS,
			allowBlank: false
		}, {
			xtype: 'fieldset',
			title: '其他选项',
			collapsible: true,
			//collapsed: true,
			autoHeight: true,
			labelAlign: 'top',
			labelWidth: 128,
			layout: 'form',
			items: [{
				xtype: 'textfield',
				id: 'displayRankingIndex' + this.MODULE_ID,
				name: 'displayRankingIndex' + this.MODULE_ID,
				value: '0',
				width: 336,
				fieldLabel: '<font color="red">显示顺序号 (必填 降序)</font>',
				regex: /^-?\d+$/,
				regexText:"只能够输入数字(最多16位)", 
				maxLength: 16, 
				allowBlank: false
			}, 
				new Ext.form.ComboBox({
				id: 'sysHoldFlag' + this.MODULE_ID,
				fieldLabel: '<font color="red">系统创建标志</font>',
				width : 60,
				store: new Ext.data.SimpleStore({
					fields: ['value', 'text'],
					data: [
						['0', '否'],
						['1', '是']
					]
				}),
				value: 0,	
				mode: 'local',
				editable: false,
				triggerAction: 'all',
				valueField: 'value',
				displayField: 'text'
			}), 
				new Ext.form.ComboBox({
				id: 'state' + this.MODULE_ID,
				fieldLabel: '<font color="red">状态</font>',
				width : 120,						
				store: new Ext.data.SimpleStore({
					fields: ['value', 'text'],
					data: [
						['0', '正常'],
						['1', '已冻结']
					]
				}),
				value: 0,	
				mode: 'local',
				editable: false,
				triggerAction: 'all',
				valueField: 'value',
				displayField: 'text'
			})
			]
		}]
	});

	this.init = function(){
		if (this.config.opCmd == App.Base.common.param.OP_CMD_ADD)
		{
			this.userTypeParentId = this.config.initValues.id;
			Ext.getCmp('userTypeParentName' + this.MODULE_ID).setValue(this.config.initValues.text + App.Base.common.param.SPLIT_CHARS_UNDELINE + this.config.initValues.id);
		}
		else if (this.config.opCmd == App.Base.common.param.OP_CMD_MODIFY)
		{
			Ext.getCmp('userTypeName' + this.MODULE_ID).setValue(this.config.initValues.text);
			this.userTypeParentId = this.config.initValues.parentId;
			Ext.getCmp('userTypeParentName' + this.MODULE_ID).setValue(this.config.initValues.parentText + App.Base.common.param.SPLIT_CHARS_UNDELINE + this.config.initValues.parentId);
			Ext.getCmp('userTypeDesc' + this.MODULE_ID).setValue(this.config.initValues.desc);
			Ext.getCmp('normalImgUrl' + this.MODULE_ID).setValue(this.config.initValues.icon);
			Ext.getCmp('expandImgUrl' + this.MODULE_ID).setValue(this.config.initValues.expandIcon);
			Ext.getCmp('displayRankingIndex' + this.MODULE_ID).setValue(this.config.initValues.displayRankingIndex);
			Ext.getCmp('sysHoldFlag' + this.MODULE_ID).setValue(this.config.initValues.sysHoldFlag);
			Ext.getCmp('state' + this.MODULE_ID).setValue(this.config.initValues.state);
		}
	};
	this.init();

	this.win = new Ext.Window({
		//id: 'win' + this.MODULE_ID,
		title: this.config.title,
		iconCls: this.config.iconCls,
		width: 420,
		minWidth: 420,
		height: 486,
		minHeight: 360,
		plain: true,
		maximizable: true,
		collapsible: true,
		constrain: true,
		modal: true,
		layout: 'fit',
		items: [this.form],
		buttonAlign: 'right',
		buttons: [{
			text: '确 定',
			handler: function(){
				if (!this.form.getForm().isValid())
				{
					App.Base.Common.func.MESSAGEBOX_SHOW({
						title: App.Base.common.param.MESSAGEBOX_NORMAL_TIPS,
						msg: '提交的数据格式不正确',
						icon: Ext.MessageBox.ERROR
					});					
					return;
				}
				if (Ext.getCmp('userTypeParentName' + this.MODULE_ID).getValue().trim().length == 0)
				{
					App.Base.Common.func.MESSAGEBOX_SHOW({
						title: App.Base.common.param.MESSAGEBOX_NORMAL_TIPS,
						msg: '上级用户类型未选择',
						icon: Ext.MessageBox.ERROR
					});	
					return;
				}

				this.action = App.Base.common.param.BUTTON_ACTION_OK;
				this.win.close();
			},
			scope: this
		},{
			text: '取 消',
			handler: function(){
				this.action = App.Base.common.param.BUTTON_ACTION_CANCEL;
				this.win.close();
			},
			scope: this
		}],
		
		listeners: {
			beforeclose: function(o){
				if (!(this.action == App.Base.common.param.BUTTON_ACTION_OK))
				{
					this.action = App.Base.common.param.BUTTON_ACTION_NONE;
				}
				if (this.handler)
				{
					this.handler.call(this.scope || this, this);
				}
				return true;
			},
			scope: this
		}

	});

	//this.win.doLayout();

	//defined methods.
    if ((typeof App.Base.SystemManage.SystemUserTypeMgrWindow.SIMULATE_SHARED_METHODS_FLAG) == "undefined")
    {
        App.Base.SystemManage.SystemUserTypeMgrWindow.SIMULATE_SHARED_METHODS_FLAG = true;   

        App.Base.SystemManage.SystemUserTypeMgrWindow.prototype.getMainPanel = function(){
            return this.win;  
        };
 
        var __ctor = function(){
        }();
    }
}